﻿using FreeRobot.Common;
using Microsoft.CSharp;
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FreeRobot
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            RobotHelper r = new RobotHelper();
            r.Excute(richTextBox1.Text);
            r.Dispose();
            //CSharpCodeProvider codeProvider = new CSharpCodeProvider();
            //ICodeCompiler icc = codeProvider.CreateCompiler();
            //string Output = "Out.exe";
            //var p = Process.GetProcessesByName("Out");
            //if(p.Length>0)
            //    p.First().Kill();
            //Button ButtonObject = (Button)sender;

            //System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
            ////Make sure we generate an EXE, not a DLL
            //parameters.GenerateExecutable = true;
            //parameters.OutputAssembly = Output;
            //CompilerResults results = icc.CompileAssemblyFromSource(parameters, richTextBox1.Text);
            //richTextBox1.Text = "";
            //if (results.Errors.Count > 0)
            //{
            //    richTextBox1.ForeColor = Color.Red;
            //    foreach (CompilerError CompErr in results.Errors)
            //    {
            //        richTextBox1.Text = richTextBox1.Text +
            //                    "Line number " + CompErr.Line +
            //                    ", Error Number: " + CompErr.ErrorNumber +
            //                    ", '" + CompErr.ErrorText + ";" +
            //                    Environment.NewLine + Environment.NewLine;
            //    }
            //}
            //else
            //{
            //    Process process = new Process();
            //    process.StartInfo.FileName = Output;
            //    process.StartInfo.UseShellExecute = false;
            //    process.StartInfo.RedirectStandardOutput = true;
            //    process.StartInfo.CreateNoWindow = true;

            //    process.Start();

            //    // 读取输出
            //    string output = process.StandardOutput.ReadToEnd();
            //    //process.WaitForExit();
            //    richTextBox1.Text += "Program Output:\n" + output;
            //    //Successful Compile
            //    richTextBox1.ForeColor = Color.Blue;
            //}
        }
    }
}
